package com.wushijia.test.java7;

import com.alibaba.druid.pool.DruidDataSource;
import com.wushijia.model.User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;

/**
 * description:java进化史
 *
 * @author yang
 * @date 2018/1/30 21:45
 */
@Slf4j
public class Jdk {

  public static void main(String[] args) {
    DataSource dataSource = new DruidDataSource();
    //try-with-resource,任何实现了java.lang.AutoCloseable的类都可用于该结构中，如JDBC Connection，PreparedStatement和ResuleSet接口都继承了这个接口
    //try关键字后面的圆括号内声明的资源，会在隐式的finally中自动关闭
    try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("")) {
      try (ResultSet resultSet = preparedStatement.executeQuery()) {
        //do something
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    //单个catch块捕捉多个异常,不能捕捉两个互有继承关系的异常
    try {

    } catch (IndexOutOfBoundsException | NullPointerException e) {
    }

    //字符串可以用作switch的参数

    //java8
    Thread thread = new Thread(() -> {
      System.out.println("我使用了Lambda表达式");
    });


  }

  public void doSomeThingForThread() {
    //或者传入方法的引用，实现单方法接口
    Thread thread1 = new Thread(this::doSomeThing1);
  }

  private void doSomeThing1() {
  }
}
